import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class GyjlyFormFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) {}

  /**
   * 添加数据
   * @remarks 
   * @returns 
   */
  addDatas(): any {
    const context = this.frameContext;
    let id = context.bindingData.getValue(['id'])
    const rep = this.frameContext.repository as BefRepository<any>;
    const datas = this.frameContext.uiState['datas'];
    let tzDadas = []
    debugger
    for (let item of datas) {
      const tzid = item.data.tzid;
      const debh = item.data.debh;
      const gyjmc = item.data.gyjmc;
      const lxmc = item.data.lxmc;
      const ggxh = item.data.ggxh;
      const dw = item.data.dw;
      const dnhsdj = item.data.dnhsdj;
      const sccj = item.data.sccj;
      const gzrq = item.data.gzrq;
      const cfwz = item.data.cfwz;
      const synx = item.data.synx;
      const lx = item.data.lx;
      tzDadas.push({
        tzid: {
          tzid: tzid,
          tzid_debh: debh,
          tzid_gyjmc: gyjmc,
          tzid_lx: {
            lx: lx,
            lx_lxmc: lxmc
          },
          tzid_ggxh: ggxh,
          tzid_dw: dw,
          tzid_dnhsdj: dnhsdj,
          tzid_sccj: sccj,
          tzid_gzrq: gzrq,
          tzid_cfwz: cfwz,
          tzid_synx: synx
        }
      })
    }
    let sl = tzDadas.length
    context.bindingData.setValue(['sl'], sl);
    // gzlxsqmx
    rep.batchAppendByPath('/' + id + '/lymxs', tzDadas).subscribe()
  }
}
